<?php
namespace Common\LibTag;
use Think\Template\TagLib;

class TagLibLists extends TagLib{
    protected $tags = array(
        //文章列表标签
        'artlist'   =>      [
            'attr'  =>      'site,cid, limit,order',
            'close' =>      1,
        ],


    );

    public function _artlist($attr,$content){

        $siteid = empty($attr['site']) ? 1 : $attr['site'];
        $limit  = empty($attr['limit'])? '10' : $attr['limit'];
        $order  = empty($attr['order'])? 'id DESC' : $attr['order'];
        $cid = empty($attr['cid']) ? 0 : $attr['cid'];



        $str =<<<str
<?php

        \$where['site_id'] = $siteid;
        \$where['status']  = 10;
        if($cid > 0){
            \$where['cid'] = $cid;
        }

    \$artLists = D('Article')->where(\$where)->order('$order')->limit($limit)->select();
    foreach(\$artLists as \$key=>\$artlist):
        
?>
str;
        $str .= $content;
        $str .='<?php endforeach;?>';
        return $str;
    }

}

